package com.taldh.mutlithread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TwinsLockTest {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        TwinsLock twinsLock = new TwinsLock();
        Runnable runnable = () -> {
            twinsLock.lock();
            try {
                System.out.println("Thread Name " + Thread.currentThread().getName() + " 拿到了锁。");
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                twinsLock.unlock();
            }
        };
        for (int i = 0; i < 10; i++) {
            executorService.execute(runnable);
        }
        executorService.shutdown();
    }
}
